package com.huluobo.a2109kotlinshopping.demo

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

/**
 *  Created by LC on 2024/1/12.
 *  2.创建Dao来进行数据库的增删改查
 *  @Insert 插入,需要写替换规则,冲突策略,当重复插入时,替换原来的内容(REPLACE)
 *  @Query("select * from user where id = :id")
 *  user 是当前的表名,where后的id是在表中的id, :id是查询方法中的参数
 */
@Dao
interface UserDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUser(user: User)

    @Delete
    fun deleteUser(user: User)

    @Update
    fun updateUser(user: User)

    @Query("select * from user where id = :id")
    fun queryUser(id: Int): User
}